package cn.yunhe.reflect;

import java.lang.reflect.InvocationTargetException;

/**
 * Created by zs on 2017/11/27.
 */
public class ReflectServiceImpl2 {
    private String name;

    public ReflectServiceImpl2(String name) {
        this.name = name;
    }

    public void sayHello() {
        System.err.println("hello" + name);
    }

    public ReflectServiceImpl2 getInstance() {
        ReflectServiceImpl2 object = null;
        try {
            object = (ReflectServiceImpl2) Class.forName("cn.yunhe.reflect.ReflectServiceImpl2").getConstructor(String.class).newInstance("张三");
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
            ex.printStackTrace();
        }
        return object;
    }

}
